package com.prs.crm.dao.cdxh.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.MoldingTeamDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.material.MaterialTeam;
import com.prs.crm.domain.cdxh.molding.Molding;
import com.prs.crm.domain.cdxh.molding.MoldingTeam;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-8 下午03:44:38
 * 简单说明
 */

public class MoldingTeamDaoImpl extends BaseDaoImpl<MoldingTeam> implements
		MoldingTeamDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public MoldingTeam getMoldingTeam(final String productCode,final String orderplan) {
		return (MoldingTeam)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(MoldingTeam.class);
				        	criteria.add(Restrictions.eq("productCode", productCode));
				        	criteria.add(Restrictions.eq("moldingOrderplan", orderplan));				        	
				        	List<MoldingTeam> result = criteria.list();
				        	if(result.size()==0){
				        		return null;
				        	}else{
				        		return result.get(0);
				        	}
				        }   
				 } );
	}

	@Override
	public void saveOrMoldingTeam(MoldingTeam moldingTeam) {
		this.getHibernateTemplate().saveOrUpdate(moldingTeam);
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<MoldingTeam> getMoldingTeamOrderpLan(final String orderplan) {
		return (List<MoldingTeam>)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(MoldingTeam.class);
				        	criteria.add(Restrictions.eq("moldingOrderplan", orderplan));		        	
				        	List<MoldingTeam> result = criteria.list();				        	
				        		return result;				        	
				        }   
				 } );
	}

}
